<script setup>

  import slVehicleViolation from './components/vehicle-violation'
  import slVehicleBreakdown from './components/vehicle-breakdown'
  import slVehicleAccident from './components/vehicle-accident'
import { onMounted, ref } from 'vue';
import { uniFetch } from '../../utils/fetch';
  import { onLoad,onShow } from '@dcloudio/uni-app'
	import {useTaskStore} from "@/store/task.js"
	const task=useTaskStore();
	const id=ref("")
onLoad(e=>{
	task.recordData.id=e.id;
	console.log(e,"e");
	startTime.value=e.actualArrivalTime
	task.recordData.startTime=startTime.value

})
const startTime=ref("")
  const endTime=ref("");
  // 回车时间
  const dataTimePicker = ref('')
  task.recordData.id=id.value;
  const submit=()=>{

	  if(task.recordData.accidentImagesList.length!==0){
	  task.recordData.accidentImagesList=task.recordData.accidentImagesList.map(({url})=>{
		  return {url}
	  })		  
	  }
	  if(task.recordData.faultImagesList.length!==0){
	  task.recordData.faultImagesList=task.recordData.faultImagesList.map(({url})=>{
	  		  return {url}
	  })	

	  }
	  console.log(task.recordData,"recorddata");
	  uniFetch({
		  url:"/driver/tasks/truckRegistration",
		  method:"POST",
		  data:task.recordData
	  }).then(res=>{
		 if(res.data.code == 200){
		 	uni.showToast({
		 		title:"操作成功",
		 		icon:"none"
		 	})
		 	uni.reLaunch({
		 		url:"/pages/task/index"
		 	})
		 }else{
		 	uni.showToast({
		 		title:res.msg,
		 		icon:"none"
		 	})
		 }
	  })
  }

</script>
<template>
  <view class="page-container">
    <scroll-view class="scroll-view" scroll-y>
      <view class="scroll-view-wrapper">
        <uni-list class="base-info">
          <uni-list-item
            title="出车时间"
            show-arrow
            :right-text="startTime"
          />
          <uni-list-item show-arrow title="回车时间">
            <template v-slot:footer>
              <uni-datetime-picker v-model="task.recordData.endTime">
                <view class="picker-value">{{
                  task.recordData.endTime || '请选择'
                }}</view>
              </uni-datetime-picker>
            </template>
          </uni-list-item>
        </uni-list>
        <sl-vehicle-violation></sl-vehicle-violation>
        <sl-vehicle-breakdown></sl-vehicle-breakdown>
        <sl-vehicle-accident></sl-vehicle-accident>
      </view>
    </scroll-view>
    <view class="toolbar">
      <button class="button" @click="submit">提交登记</button>
    </view>
  </view>
</template>

<style lang="scss" scoped>
  @import './index.scss';
</style>
